package org.bees.cms.web.util.velocity.renderer;

import java.io.Serializable;

import net.sf.json.JSONObject;

import org.bees.cms.web.util.Beans;
import org.bees.cms.web.util.velocity.element.Link;

public class LinkRenderer implements Renderer {
	private Link link = new Link();

	@Override
	public void initialize(JSONObject json) throws Exception {
		link.from(json);
	}

	@Override
	public String render(Serializable t) throws Exception {
		String value = Beans.getString(t, link.getProperty());
		String href = link.getContext() + link.getAction() + (link.getAction().equals("") ? "" : link.getAction().contains("?") ? "&" : "?") + link.getName() + (link.getName().equals("") ? "" : "=") + value;
		link.setHref(href);
		return link.toHTML();
	}

	@Override
	public void destroy() throws Exception {
		link = null;
	}

}
